package band.wukong.practice.javase.core.io.readerandwriter;

import java.io.*;

/**
 * Desc:
 * Author: sunjs
 * Date: 2009-11-13 9:31:09
 */
public class TestReaderWiter {
    //    static final String FILE_IN = "E:\\somecode\\TestJava\\src\\com\\jsun\\javase\\io\\doc\\poem.txt";
    static final String FILE = "E:\\workspace\\TestJava\\src\\com\\jsun\\javase\\io\\doc\\poem.txt";

    public static void main(String[] args) throws Exception {
        InputStream fi = new FileInputStream(FILE);
//        Reader Reader = new InputStreamReader(fi);
        Reader Reader = new InputStreamReader(fi, "UTF-8");
        BufferedReader in = new BufferedReader(Reader);


        String s1;
        int lineNum = 1;
        StringBuilder sb = new StringBuilder();
        while ((s1 = in.readLine()) != null) {
            sb.delete(0, sb.length());
            sb.append("Line").append(lineNum++).append(": ").append(s1);
            System.out.println(sb);
        }
//        in.close();


        System.out.println("===============================");
        String poem = "\n\n宣武区的天是晴朗的天，\n通州区的人民好喜欢。\n眼望丰台高声喊，\n我爱你，海淀！";

        OutputStream os = new FileOutputStream(FILE, true);
//        Writer writer = new OutputStreamWriter(os);
        Writer writer = new OutputStreamWriter(os, "UTF-8");
        PrintWriter out = new PrintWriter(writer);
        out.println(poem);
        out.close();

        String s2;
        while ((s2 = in.readLine()) != null) {
            System.out.println(s2);
        }
        in.close();
    }
}
